﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using RTUParameterConfig.Class;

namespace RTUParameterConfig
{
    public partial class RainFallSetting : Form
    {
        public RainFallSetting()
        {
            InitializeComponent();
            cbbSd.Properties.Items.AddRange(Common.OpenStatus);
            cbbSd.SelectedIndex = 0;
            SetValue();
        }

        /// <summary>
        /// 设置雨量计配置
        /// </summary>
        public void SetValue()
        {
            try
            {
                nud1.Value = Convert.ToDecimal(ParameterConfig.rtuConfigInfo.RainAlarm / 10.0);
                cbbSd.SelectedIndex = ParameterConfig.rtuConfigInfo.RainTimeReport;
                //nud2.Value = Convert.ToDecimal(BitConverter.ToUInt32(ParameterConfig.rtuConfigInfo.DayRain.Reverse<byte>().ToArray(), 0) / 10.0);
                //nud3.Value = Convert.ToDecimal(BitConverter.ToUInt32(ParameterConfig.rtuConfigInfo.TotalRain.Reverse<byte>().ToArray(), 0) / 10.0);
            }
            catch
            {
                Common.ShowErrorMessage("加载高级设置参数失败！");
            }

        }

        /// <summary>
        /// 获取雨量计配置
        /// </summary>
        public void GetValue()
        {
            ParameterConfig.rtuConfigInfo.RainAlarm = Convert.ToByte(nud1.Value * 10);
            ParameterConfig.rtuConfigInfo.RainTimeReport = Convert.ToByte(cbbSd.SelectedIndex);
            //ParameterConfig.rtuConfigInfo.DayRain = BitConverter.GetBytes(Convert.ToUInt32(nud2.Value * 10)).Reverse<byte>().ToArray();
            //ParameterConfig.rtuConfigInfo.TotalRain = BitConverter.GetBytes(Convert.ToUInt32(nud3.Value * 10)).Reverse<byte>().ToArray();
        }

        /// <summary>
        /// 关闭前保存修改的配置信息
        /// </summary>
        private void WaterLevelSetting_FormClosing(object sender, FormClosingEventArgs e)
        {
            GetValue();
            this.Dispose();
        }
    }
}
